﻿using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
namespace INTEX.DataBase.Tools
{
    public partial class INTEXDBC
    {
        public DataSet QuerySTUELI(DataRow dwData, int option = 1)
        {
            DataSet setReturn = new DataSet();
            DataSet Result = new DataSet();
            DataTable tbLocal = null;
            OracleCommand or1;

            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "SELECT * FROM STUELI WHERE  "
                        + "  STUELIMANDANT=:STUELIMANDANT AND STUELISAPD=:STUELISAPD ";
                    or1.Parameters.Add("STUELIMANDANT", OracleType.NVarChar).Value = dwData["STUELIMANDANT"].ToString();
                    or1.Parameters.Add("STUELISAPD", OracleType.NVarChar).Value = dwData["STUELISAPD"].ToString();
                    break;
                case 2:
                    or1.CommandText = "SELECT * FROM STUELI WHERE  "
        + "  STUELIMANDANT=:STUELIMANDANT AND STUELISAPD=:STUELISAPD ";
                    or1.Parameters.Add("STUELIMANDANT", OracleType.NVarChar).Value = dwData["STUELIMANDANT"].ToString();
                    or1.Parameters.Add("STUELISAPD", OracleType.NVarChar).Value = dwData["STUELISAPD"].ToString();
                    break;
                case 3:
                    or1.CommandText = "SELECT DISTINCT TRIM(SUBSTR(STUELISAPD,15,20)) AS C, DECODE(TRIM(SUBSTR(STUELIDATEN,55,2)),'R','XXX','FL','FACE:','GS','GROUND:') AS A,"
                        + "  TO_NUMBER(SUBSTR(STUELIDATEN,1,4))*0.1||'%'||TRIM(STUELISASB) AS B ,SUBSTR(STUELIDATEN,1,4) AS D"
                        + "    FROM STUELI WHERE SUBSTR(STUELIDATEN,55,2) IN ('R ','FL','GS')"
                        + "     AND STUELIMANDANT=:STUELIMANDANT AND SUBSTR(STUELISAPD,15,20)=:STUELISAPD  "
                        + " ORDER BY C,A,D DESC";
                    or1.Parameters.Add("STUELIMANDANT", OracleType.NVarChar).Value = dwData["STUELIMANDANT"].ToString();
                    or1.Parameters.Add("STUELISAPD", OracleType.NVarChar).Value = Left(dwData["STUELISAPD"].ToString(), 20);
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
            {
                tbLocal = Result.Tables[0];
                tbLocal.TableName = "STUELI";
            }

            setReturn.Merge(Result);
            return setReturn;
        }
    }
}
